package com.beta.restapi.controller;

import com.beta.common.web.ContentType;
import com.beta.restapi.internal.Consts;
import com.beta.service.IUsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by vector on 2016/11/22.
 */
@Api(tags = {"Device"})
@RestController
@RequestMapping(Consts.API_PATH_PREFIX)
public class DeviceController extends BaseController {

    @Autowired
    private IUsersService userService;

    @ApiOperation(value = "bundingUserCid", notes = "绑定设备ID,用于消息推送")
    @GetMapping(value = "/bundingcid/{userType}/{cid}/{deviceType}", produces = {ContentType.JSON})
    public Object bungingUserCid(@RequestHeader(Consts.HEADER_AUTH_KEY) String token,
                                 @PathVariable("userType") String userType,
                                 @PathVariable("cid") String cid,
                                 @PathVariable("deviceType") String deviceType) {
        userService.executeBungingUserCid(getCurrentUserId(), getCurrentUserType(), cid, deviceType);
        return ok();
    }

    @ApiOperation(value = "unbundingCid", notes = "解绑设备ID")
    @GetMapping(value = "/unbundingcid/{cid}", produces = {ContentType.JSON})
    public Object unbungingCid(@RequestHeader(Consts.HEADER_AUTH_KEY) String token, @PathVariable("cid") String cid) {
        userService.executeUnBundingCid(cid);
        return ok();
    }

}
